
package com.rt.schedulenew.core.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AppWebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/META-INF/resources/")
                .setCachePeriod(0);
    }

//    @Bean
//    public AppAuthInterceptor appAuthInterceptor() {
//        return new AppAuthInterceptor();
//    }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(appAuthInterceptor()).order(1)
//                .excludePathPatterns("/rtAuth/**", "/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**", "/document.html/**")
//                .addPathPatterns("/**");
//    }

    /**
     * 跨域请求配置
     *
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //配置允许跨域的路径
        registry.addMapping("/**")
                //配置允许访问的跨域资源的请求域名
                .allowCredentials(true)
                .allowedOrigins("*")
                //配置允许访问该跨域资源服务器的请求方法
                .allowedMethods("*")
                //配置允许请求 头部head的访问
                .allowedHeaders("*");
    }
}
